// $Id$

var maxItems;
var currentIndex=0;
var active = true;

Drupal.behaviors.wowitemcache_reloadcache = function (context) {
  $('#stop_button').click(function() {
    active = false;
    return false;
  });
  $('#begin_button').click(function() {
    active = true;
    nextItem();
    return false;
  });
  maxItems = items.length;

}


function nextItem() {
  if((items.length > 0)&&(active)) {
    newitem = items.pop();
    currentIndex++;
    $.get(ajax_link + '/' + newitem, function(data) {
      $('#out').append(data + '<br />');
      percent = (currentIndex / maxItems) * 100;
      $("#progress .filled").css('width',percent);
      $("#progress .percentage").html(Math.round(percent) + '%');
      $("#progress .message").html('[' + currentIndex + '/' + maxItems + ']');
      nextItem();
    });
  }
}